import { createApp } from 'vue'
import App from './app.vue'
import '@/lib/css/reset.scss'
import './style.scss'
import Api from './api'
import { Api as Apix } from './api'
import { setupAxios } from '@/lib/js/http'
import { ServerTypeEnum } from '@/lib/js/http/enums'
import { setupLoginStore, clearLoginStore } from '@/lib/js/hooks'
import { createLogin } from '@/lib/components/Login'
import { router } from './router'
import store from './store'
import ArrowsIcon from './components/arrows-icon.vue'
import ShootingStar from './components/shooting-star.vue'
import DownloadBar from './components/download-bar.vue'
import BlinkStar from './components/blink-star.vue'
import { AutoHeightBlock } from '@/lib/components'
import { Dialog, ActionSheet, Toast } from 'vant'

// import { Dialog } from 'vant'
import metro from './directive/metro'

setupLoginStore()

// 配置axios
setupAxios({
  serverType: ServerTypeEnum.old,
  loginStatusCatch: () => {
    clearLoginStore()
    if(/\/main/.test(window.location.href)){
      Toast.fail('请重新登录')
      setTimeout(() => {
        window.location.href = `${window.location.origin}${window.location.pathname}`
      }, 500)
      return
    }
    createLogin(() => {
      (Apix as any).Info.getUserInfo().then((res: any) => {
        const { result: { user_info : { hey_id:heyId, nick_name: nickName } } } = res
        localStorage.setItem('currentUserHeyId', heyId)
        localStorage.setItem('currentUserNickName', nickName)
        window.location.reload()
      })
    })
  }
})

const app = createApp(App)
app.use(router)
app.use(store)
app.use(metro)
app.use(Toast)
app.component('ArrowsIcon', ArrowsIcon)
app.component('ShootingStar', ShootingStar)
app.component('BlinkStar', BlinkStar)
app.component('AutoHeightBlock', AutoHeightBlock)
app.component('DownloadBar', DownloadBar)
app.use(Api)
// app.use(Vant)
app.use(Dialog)
app.use(ActionSheet)
app.mount('#app')



